<div class="row"> <h3 class="page-header">轮播图列表</h3></div>
<div class="row">
    <div class="panel panel-default">
        <div class="panel-body">
            <label><a class="btn btn-primary addText" data-id='{$list.id}'>添加</a></label>
            <form action='{:U("Slide/index")}' class="form-inline text-right m-b-5 fr" >
                名称：<input type="text" name='name' value='{$Think.get.name}' class="form-control mr20 w150">
                分类：<select name='cid' class="form-control mr20 w150">
                    <option value='-1'>全部</option>
                    <volist name="classifyList" id="classifyList_now">
                        <option value='{$classifyList_now.id}' <eq name='Think.get.cid' value="$classifyList_now.id">selected</eq>>{$classifyList_now.name}</option>
                    </volist>
                </select>
                状态：<select name='status' class="form-control mr20 w150">
                    <option value='-1'>全部</option>
                    <option value='1' <eq name='Think.get.status' value='1'>selected</eq> >启用</option>
                    <option value='0' <eq name='Think.get.status' value='0'>selected</eq> >禁用</option>
                </select>
                <button class="btn btn-primary" type="submit">搜索</button>
            </form>
            <div class="table-responsive">
                <table class="table table-striped table-bordered table-hover">
                    <thead>
                    	<tr>
                       		<th width="60">序号</th>
                            <th>名称</th>
                            <th>图片</th>
                            <th>链接</th>
                            <th width="75">排序</th>
                            <th width="75">状态</th>
                            <th width="120">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <empty name="list">
                            <tr><td colspan="7" align="center">暂无信息</td></tr>
                        </empty>
                        <volist name="list" id="list">
                            <tr>
                                <td>{$i}</td>
                                <td>{$list.name}</td>
                                <td><img src="{$list.pic}" width="100" height="50"></td>
                                <td><a href="{$list.link}" target="_blank">{$list.link}</a></td>
                                <td><input class="setSort" type="text" size="2" data-url="{:U('Slide/setSort?id='.$list['id'])}" value="{$list.sort}"></td>
                                <td><button class='btn <eq name="list.status" value="1">btn-primary<else />btn-default</eq> btn-sm setStatus' type="button" data-url='{:U("Slide/setStatus?id=".$list["id"])}' data-status="{$list.status}"><eq name="list.status" value='1'>启用<else />禁用</eq></button></td>
                                <td>
                                    <a class="btn-sm btn btn-default editText" data-id='{$list.id}'>修改</a>
                                    <button data-url='{:U("Slide/del?id=".$list["id"])}' class="btn-sm btn btn-default delBtn" type="button">删除</button>
                                </td>
                            </tr>
                        </volist>
                    </tbody>
                </table>
            </div>
            {$page}
        </div>
    </div>
</div>

<div id="myModal" class="modal fade in" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content">
            <form action="{:U('Slide/add')}" id="myform" class="form-horizontal" data-callback="_form_defult_callback">
                <div class="modal-header">
                    <button data-dismiss="modal" class="close" type="button">×</button>
                    <h4 class="modal-title">轮播图管理</h4>
                </div>
                 <div class="modal-body">
                <div class="form-group">
                    <label class="col-sm-3 control-label">名称：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control required" name="name" >
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">分类：<span class="c-red">*</span></label>
                     <div class="col-sm-4 input-group">
                        <select class="form-control required" name="cid">
                            <volist name='classifyList' id='list'>
                                <option value="{$list.id}">{$list.name}</option>
                            </volist>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">URL地址：</label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control url" name="link">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">图片：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                        <div class="uploadify-div"></div>
                        <button type="button" name="pic" class="upload" id="upload">选择图片</button>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">排序：</label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control digits" name="set_sort" value="100">
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">状态：</label>
                    <div class="col-sm-4 input-group">
                        <label class="radio-inline">
                            <input type="radio" value="1" name="set_status" checked>启用
                        </label>
                        <label class="radio-inline">
                            <input type="radio" value="0" name="set_status">禁用<BR>
                        </label>
                    </div>
                </div>
                </div>
                <div class="modal-footer">
                    <button data-dismiss="modal" class=" btn btn-default" type="button">关闭</button>
                    <button class="btn btn-primary" type="submit">保存</button>
                </div>
                <input type='hidden' name='id' value='{$info.id}'>
            </form>
        </div>
    </div>
</div>


<script type="text/javascript">

$(function(){
    $('.addText').click(function(){
        $('#myform')[0].reset();
        $('.uploadify-div').html("");
        $('#myModal').modal('show');
    });

    $('.editText').click(function(){
        $('#myform')[0].reset();
        var id = $(this).data('id'); waiting();
        $.get('{:U("Slide/edit")}', {id: id}, function(data){
            complete();
            if(data.status == 1){
                var _get_info = data.info;
                $('#myform input[name="id"]').val(_get_info.id);
                $('#myform input[name="name"]').val(_get_info.name);
                $('#myform select[name="cid"]').val(_get_info.cid);
                $('#myform input[name="link"]').val(_get_info.link);
                $('#myform input[name="set_sort"]').val(_get_info.sort);          
                $("#myform :radio[name=set_status][value='"+_get_info.status+"']").attr("checked",true)
                
                var div = $('.uploadify-div');
                if(_get_info.pic.length > 0){
                    //有图片
                    var html = '<li>';
                    html += "<img src='"+_get_info.pic+"' />";
                    html += "<input type='hidden' name='pic' value='"+_get_info.pic+"' /><span style='color:blue;cursor:pointer;' class='uploadifyDel'>删除</span></li>";
                    div.html(html);
                }else{
                    div.html("");
                }

                $('#myform').attr('action', '{:U("Slide/edit")}');
                $('#myModal').modal('show');

            }else{
                showInfo(data.info);
                setTimeout('_form_defult_callback()', 1600);
            }
        });
    });

    $('.open').click(function(){
        if($(this).data('open') == 0){
            $(this).removeClass('fa-minus').addClass('fa-plus');
            $('.level'+$(this).data('id')).addClass('hide');
        }else{
            $(this).removeClass('fa-plus').addClass('fa-minus');
            $('.level'+$(this).data('id')).removeClass('hide');
        }
        $(this).data('open', $(this).data('open') == 1 ? 0 : 1);
    });

})
</script>